//logs.js
const util = require('../../utils/util.js')

Page({
  
  onReady: function () {
    this.setData({
        isempty: true
    })
    console.log(this)
    var app = getApp();
    var testUrl = app.testUrl;
    var that = this;
    var articleList;
  
    //获取所有文章
    wx.request({
      url: testUrl + '/article/search.do?page=1&rows=20',
      method:"POST",
      data:{
        userId: app.globalData.openid,
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        if (res.data.rows.length > 0) {
          that.setData({
            isempty: false
          });
        }
        //获取返回数据
        console.log(res)
        articleList = res.data.rows;
        //讲图片json字符串转为json对象
        var app = getApp()
        for (var i = 0; i < articleList.length; i++) {
          if (articleList[i].articleImg!=''){
            articleList[i].articleImg = JSON.parse(articleList[i].articleImg);
          }
          
          articleList[i].createTime = app.dateto(articleList[i].createTime)
          // getUserInfo(i);
        }
        that.setData({
          articleList: res.data.rows
        });
        console.log(that.data);
      }
    });
  },
  toDetail: function (event) {
    var articleId = event.currentTarget.dataset.id;//文章id
    wx.navigateTo({
      url: '/pages/article/article?id=' + articleId
    })
  },



  tonewArticle: function (event) {
    wx.navigateTo({
      url: '/pages/newArticle/newArticle'
    })
  },

  data: {

  },
  onLoad: function () {
    this.setData({
      logs: (wx.getStorageSync('logs') || []).map(log => {
        return util.formatTime(new Date(log))
      })
    })
  }
})
